<template>
    <div>
        <h1>添加</h1>
        <table class="table table-bordered">
            <tr>
                <td>用户名</td>
                <td><input type="text" v-model="str.yongHU"></td>
            </tr>
            <tr>
                <td>房号名称</td>
                <td><input type="text" v-model="str.name"></td>
            </tr>
            <tr>
                <td>门店</td>
                <td><input type="text" v-model="str.shop"></td>
            </tr>
            <tr>
                <td>地址</td>
                <td><input type="text" v-model="str.addr"></td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="stat" v-model="str.state":value="0">禁用
                    <input type="radio" name="stat" v-model="str.state":value="1">启用
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="修改" @click="Add"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';

let route = useRoute();
let router = useRouter();
let data: any = reactive({
    str: {

        "yongHU": "",
        "name": "",
        "shop": "",
        "addr": "",
        "state": 0,

    },
});
let { str } = toRefs(data);

const Add = () => {
    if(str.value.yongHU == "" || str.value.name == "" || str.value.shop == "" || str.value.addr == "") {
        alert("请输入完整信息");
        return;
    }
 
    let obj = {
        id: route.query.id,
        "yongHU": str.value.yongHU,
        "name": str.value.name,
        "shop": str.value.shop,
        "addr": str.value.addr,
        "state": str.value.state,
    }

    axios({
        url: '/api/HouseN/Update',
        method: 'put',
        data: obj
    }).then((res) => {
       if (res.data.data == 1) {
            alert("修改成功");
            router.push('/list');
        } else {
            alert("修改失败");
            return;
       }
    })

}

onMounted(() => {
    FanTian();
})
const FanTian = () => {
    let obj = {
        id: route.query.id,
    }
    axios({
        url: '/api/HouseN/FanTian',
        method: 'get',
        params: obj
    }).then((res) => {
        str.value = res.data.data
    })
}

</script>

<style scoped></style>